{extend name="base/main" /}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>角色管理 / 访问授权  角色名称：【{$group_role['title']}】</h5>
        </div>
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div class="col-sm-12">
                        <div class="tabs-container">
                            <?php if($type == 'access'){ ?>
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="{:url('author/access',['role_id'=>$role_id])}">访问授权</a></li>
                                <li class=""><a href="{:url('author/member',['role_id'=>$role_id])}">成员授权</a></li>
                            </ul>
                            <div class="tab-content">
                                <div class="tab-pane active">
                                    <div class="panel-body">
                                        <form id="f" action="{:url('author/access')}" class="form-horizontal m-t">
                                            <div class="col-sm-12">
                                                <ul class="todo-list ui-sortable">
                                                    {php}
                                                    foreach( $node_list as $key=>$node ) {
                                                    {/php}
                                                    <li>
                                                        <input type="checkbox" value="{$node.id}" <?php if(in_array($node['id'],explode(',',$group_role['rules']))){echo "checked";}?> name="rules[]" class="i-checks first_menu  first_{$node.id}" id="f-{$node.id}">
                                                        <label class="" for="f-{$node.id}">{$node.title}管理</label>
                                                        <ul class="todo-list ui-sortable">
                                                            {present name="node['child']"}
                                                            {volist name="node['child']" id="child"}

                                                            <li>
                                                                <input type="checkbox" value="{$child.id}" <?php if(in_array($child['id'],explode(',',$group_role['rules']))){echo "checked";}?> name="rules[]" class="i-checks second_menu second_{$child.id}" data-first="{$node.id}" id="f-{$child.id}">
                                                                <label class="" for="f-{$child.id}">{$child.title}</label>
                                                                <ul class="todo-list ui-sortable">
                                                                    <li>{notempty name="child['operator']"}
                                                                        {volist name="child['operator']" id="op"}

                                                                        <span>
                                                                        <input type="checkbox" value="{$op.id}"  <?php if(in_array($op['id'],explode(',',$group_role['rules']))){echo "checked";}?> name="rules[]" class="i-checks third_box" data-first="{$node.id}" data-second="{$child.id}" id="f-{$op.id}">
                                                                        <label class="" style="font-weight: 100" for="f-{$op.id}">{$op.title}&nbsp;&nbsp;&nbsp;&nbsp;</label>
                                                                        </span>

                                                                        {/volist}
                                                                        {/notempty}</li>
                                                                </ul>
                                                            </li>
                                                            {/volist}
                                                            {/present}
                                                        </ul>
                                                    </li>
                                                    {php} } {/php}
                                                </ul>
                                            </div>
                                            <div class="form-group">
                                                <div class="col-sm-2 col-sm-offset-1" style="margin-top:30px;">
                                                    <input type="hidden" value="{$role_id}" name="role_id"/>
                                                    <button class="btn btn-primary" type="submit">提交</button>
                                                    <a href="{:url('AuthRole/index')}" class="btn btn-default" >返回</a>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                            <?php } ?>
                            <?php if($type == 'member'){ ?>
                            <ul class="nav nav-tabs">
                                <li class=""><a href="{:url('author/access',['role_id'=>$role_id])}">访问授权</a></li>
                                <li class="active"><a href="{:url('author/member',['role_id'=>$role_id])}">成员授权</a></li>
                            </ul>
                            <div class="tab-content">
                                <div class="tab-pane active">
                                    <div class="panel-body">
                                        <table class="table table-hover ">
                                            <thead>
                                            <tr>
                                                <th>用户帐号</th>
                                                <th>昵称</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            {volist name="list" id="vo"}
                                            <tr>
                                                <td>{$vo.username}</td>
                                                <td>{$vo.nickname}</td>
                                                <td>
                                                    <a href="{:url('author/cleanbind',['uid'=>$vo['uid'],'role_id'=>$vo['role_id']])}" class="btn btn-xs btn-white" ><i class="fa fa-times-circle"></i> 撤销授权 </a>
                                                </td>
                                            </tr>
                                            {/volist}
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                            <?php } ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $('.first_menu').on('ifClicked', function() {
        if( $(this).parent().find("input").is(':checked') ) {
            $(this).parent().parent().find("input").iCheck('uncheck');
        } else {
            //选中
            $(this).parent().parent().find("input").iCheck('check');
        }
    });

    $('.second_menu').on('ifClicked', function() {
        var firstId = $(this).attr( 'data-first' );
        if( $(this).is(':checked') ) {
            $(this).parent().parent().find("input").iCheck('uncheck');

            var checked = 0;
            $(this).parent().parent().parent('ul').find('.second_menu').each(function() {
                if( $(this).is(':checked') ) {
                    checked = checked+1;
                }
            });
            if( checked == 0 ) {
                $('.first_'+firstId).iCheck('uncheck');
            }
        } else {
            //选中
            $(this).parent().parent().find("input").iCheck('check');
            $('.first_'+firstId).iCheck('check');
        }
    });

    $('.third_box').on('ifClicked', function() {
        var firstId  = $(this).attr( 'data-first' );
        var secondId = $(this).attr( 'data-second' );
        if( $(this).is( ':checked' ) ) {
        } else {
            //选中
            $('.first_'+firstId).iCheck('check');
            $('.second_'+secondId).iCheck('check');
        }
    });
</script>
{/block}